package com.zbkj.admin.controller.merchant.v2;

import com.zbkj.dal.base.enums.OrderStatusEnums;
import com.zbkj.dal.base.enums.show.EnumInterface;
import com.zbkj.dal.base.enums.show.EnumShowVO;
import com.zbkj.dal.base.page.CommonPage;
import com.zbkj.dal.base.result.CommonResult;
import com.zbkj.dal.common.utils.SecurityUtil;
import com.zbkj.dal.pojo.request.OrderSendRequest;
import com.zbkj.dal.pojo.request.order.merchant.AdminMerchantRentOrderQueryRequest;
import com.zbkj.dal.pojo.request.order.merchant.AdminMerchantRentOrderVerifyRequest;
import com.zbkj.dal.pojo.response.order.merchant.MerchantOrderDetailNewResponse;
import com.zbkj.dal.pojo.response.order.merchant.MerchantOrderPageNewResponse;
import com.zbkj.dal.pojo.vo.LogisticsResultVo;
import com.zbkj.service.service.order.merchant.AdminMerchantRentOrderV2Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wangzhengyan
 * @date 2024/4/8 5:14 PM
 */
@Api(tags = "商户后台-订单-承享订单")
@RestController
@RequestMapping("api/admin/merchant/order/rent")
public class MerchantRentOrderV2Controller {

    @Resource
    private AdminMerchantRentOrderV2Service adminMerchantService;

    /**
     * 订单状态
     *
     * @return {@link OrderStatusEnums}
     */
    @GetMapping("/order/status")
    @ApiOperation(value = "订单状态列表")
    public CommonResult<List<EnumShowVO<Integer>>> orderStatus() {
        return CommonResult.success(adminMerchantService.getOrderStatusList());
    }

    // 获取商户后台-订单管理-承享订单列表
    @PreAuthorize("hasAuthority('merchant:order:page:list')")
    @ApiOperation(value = "商户端订单分页列表") //配合swagger使用
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public CommonResult<CommonPage<MerchantOrderPageNewResponse>> getList(@Validated @RequestBody AdminMerchantRentOrderQueryRequest request) {
        return CommonResult.success(CommonPage.restPage(adminMerchantService.getAdminMerchantOrderList(request)));
    }

    // 获取商户后台-订单管理-承享订单详情
    @PreAuthorize("hasAuthority('merchant:order:detail')")
    @ApiOperation(value = "商户端订单详情") //配合swagger使用
    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    public CommonResult<MerchantOrderDetailNewResponse> getDetail(@RequestParam("orderNo") String orderNo) {
        return CommonResult.success(adminMerchantService.getAdminMerchantOrderDetail(orderNo));
    }

    // 确认收货
    @ApiOperation(value = "确认收货")
    @RequestMapping(value = "/confirmReceipt", method = RequestMethod.POST)
    public CommonResult<Boolean> confirmReceipt(@RequestParam("orderNo") String orderNo) {
        return CommonResult.success(adminMerchantService.confirmReceiptMerchantOrder(orderNo));
    }

    // 确认提货
    @ApiOperation(value = "确认提货")
    @RequestMapping(value = "/confirmDelivery", method = RequestMethod.POST)
    public CommonResult<Boolean> confirmDelivery(@RequestParam("orderNo") String orderNo, @RequestParam("deliveryCode") String deliveryCode) {
        SecurityUtil.getLoginUserVo();
        return CommonResult.success(adminMerchantService.confirmDeliveryMerchantOrder(orderNo, deliveryCode));
    }

    // 发货
    @ApiOperation(value = "发货")
    @RequestMapping(value = "/delivery", method = RequestMethod.POST)
    public CommonResult<Boolean> delivery(@RequestBody OrderSendRequest request) {
        SecurityUtil.getLoginUserVo();
        return CommonResult.success(adminMerchantService.deliveryMerchantOrder(request));
    }

    // 查看订单物流轨迹
    @ApiOperation(value = "查看订单物流轨迹")
    @RequestMapping(value = "/logistics", method = RequestMethod.GET)
    public CommonResult<List<LogisticsResultVo>> getLogistics(@RequestParam("orderNo") String orderNo) {
        return CommonResult.success(adminMerchantService.getLogisticsMerchantOrder(orderNo));
    }

    // 验货
    @ApiOperation(value = "验货")
    @RequestMapping(value = "/verify", method = RequestMethod.POST)
    public CommonResult<Boolean> verify(@Validated @RequestBody AdminMerchantRentOrderVerifyRequest request) {
        return CommonResult.success(adminMerchantService.checkMerchantOrder(request));
    }

    // 催收
    @ApiOperation(value = "催收")
    @RequestMapping(value = "/urge", method = RequestMethod.POST)
    public CommonResult<Boolean> urge(@RequestParam("orderNo") String orderNo) {
        return CommonResult.success(adminMerchantService.urgeMerchantOrder(orderNo));
    }


}
